<?php

namespace App\Models\lazada;

use App\Models\AdminModel;
use App\Models\cainiao\AsnModel;
use App\Models\cainiao\NotifyModel;
use App\Models\CustomerModel;
use App\Models\StaffModel;
use App\Models\TakeOrderModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model as BaseModel;
use App\Models\lazada\NodeModel;


class NodeRecordModel extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_lazada_sop_node_record';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    const TYPE_UPDATE = 1;
    const TYPE_CALLBACK = 2;

    const TYPES = [
        self::TYPE_UPDATE => '更新节点',
        self::TYPE_CALLBACK => '回传节点',
    ];

    const RECORD_TYPE_NOTIFY = 1;
    const RECORD_TYPE_ASN = 2;
    const RECORD_TYPE_TAKE_ORDER = 3;
    const RECORD_TYPES = [
        self::RECORD_TYPE_NOTIFY => '大包',
        self::RECORD_TYPE_ASN => '小包',
        self::RECORD_TYPE_TAKE_ORDER => '提单',
    ];



    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];



    //创建人
    public function create_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }

    //创建人
    public function create_user(): HasOneThrough {
        return $this->HasOneThrough(StaffModel::class, AdminModel::class, 'id', 'id', 'created_admin_id', 'staff_id');
    }

    //节点
    public function node(): BelongsTo {
        return $this->belongsTo(NodeModel::class, 'node_id');
    }

    //大包号
    public function notify(): BelongsTo {
        return $this->belongsTo(NotifyModel::class, 'notify_id');
    }

    //小包号
    public function asn(): BelongsTo {
        return $this->belongsTo(AsnModel::class, 'asn_id');
    }

    //提单号
    public function take_order(): BelongsTo {
        return $this->belongsTo(TakeOrderModel::class, 'take_order_id');
    }

    //客户
    public function customer(): BelongsTo {
        return $this->belongsTo(CustomerModel::class, 'customer_id');
    }
}
